package com.add.system;

import com.lineage.data.cmd.CreateNewItem;
import com.lineage.server.datatables.ItemTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_CloseList;
import com.lineage.server.serverpackets.S_ItemCount;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.log.PlayerLogUtil;
import com.lineage.server.world.World;
import java.sql.Timestamp;
import java.util.Random;

public class L1Blend {
  private int _npcid;
  
  private String _action;
  
  private String _note;
  
  private int _checkLevel;
  
  private int _checkClass;
  
  private int _rnd;
  
  private int _hpConsume;
  
  private int _mpConsume;
  
  private int[] _materials;
  
  private int[] _materials_count;
  
  private int[] _materials_enchants;
  
  private int _new_item;
  
  private int _new_item_counts;
  
  private int _new_Enchantlvl_SW;
  
  private int _new_item_Enchantlvl;
  
  private int _new_item_Bless;
  
  private int _residue_item;
  
  private int _residue_count;
  
  private int _replacement_count;
  
  private boolean _inputamount;
  
  private boolean _all_in_once;
  
  private int _bonus_item;
  
  private int _bonus_item_count;
  
  private int _bonus_item_enchant;
  
  private String _sucesshtml;
  
  private String _failhtml;
  
  private String _Allmessage;
  
  private String _runmessage;
  
  private int _itembroad;
  
  private String _othermessage;
  
  private int _itemran;
  
  private int _itemranup;
  
  public int get_npcid() {
    return this._npcid;
  }
  
  public void set_npcid(int npcid) {
    this._npcid = npcid;
  }
  
  public String get_action() {
    return this._action;
  }
  
  public void set_action(String action) {
    this._action = action;
  }
  
  public String get_note() {
    return this._note;
  }
  
  public void set_note(String note) {
    this._note = note;
  }
  
  public int getCheckLevel() {
    return this._checkLevel;
  }
  
  public void setCheckLevel(int checkLevel) {
    this._checkLevel = checkLevel;
  }
  
  public int getCheckClass() {
    return this._checkClass;
  }
  
  public void setCheckClass(int checkClass) {
    this._checkClass = checkClass;
  }
  
  public int getRandom() {
    return this._rnd;
  }
  
  public void setRandom(int rnd) {
    this._rnd = rnd;
  }
  
  public int getHpConsume() {
    return this._hpConsume;
  }
  
  public void setHpConsume(int hpConsume) {
    this._hpConsume = hpConsume;
  }
  
  public int getMpConsume() {
    return this._mpConsume;
  }
  
  public void setMpConsume(int mpConsume) {
    this._mpConsume = mpConsume;
  }
  
  public final int[] getMaterials() {
    return this._materials;
  }
  
  public void setMaterials(int[] needids) {
    this._materials = needids;
  }
  
  public final int[] getMaterials_count() {
    return this._materials_count;
  }
  
  public final void setMaterials_count(int[] needcounts) {
    this._materials_count = needcounts;
  }
  
  public final int[] get_materials_enchants() {
    return this._materials_enchants;
  }
  
  public final void set_materials_enchants(int[] needenchants) {
    this._materials_enchants = needenchants;
  }
  
  public int getNew_item() {
    return this._new_item;
  }
  
  public void setNew_item(int new_item) {
    this._new_item = new_item;
  }
  
  public int getNew_item_counts() {
    return this._new_item_counts;
  }
  
  public void setNew_item_counts(int new_item_counts) {
    this._new_item_counts = new_item_counts;
  }
  
  public int getNew_Enchantlvl_SW() {
    return this._new_Enchantlvl_SW;
  }
  
  public void setNew_Enchantlvl_SW(int new_Enchantlvl_SW) {
    this._new_Enchantlvl_SW = new_Enchantlvl_SW;
  }
  
  public int getNew_item_Enchantlvl() {
    return this._new_item_Enchantlvl;
  }
  
  public void setNew_item_Enchantlvl(int new_item_Enchantlvl) {
    this._new_item_Enchantlvl = new_item_Enchantlvl;
  }
  
  public int getNew_item_Bless() {
    return this._new_item_Bless;
  }
  
  public void setNew_item_Bless(int new_item_bless) {
    this._new_item_Bless = new_item_bless;
  }
  
  public int getResidue_Item() {
    return this._residue_item;
  }
  
  public void setResidue_Item(int residueitem) {
    this._residue_item = residueitem;
  }
  
  public int getResidue_Count() {
    return this._residue_count;
  }
  
  public void setResidue_Count(int residuecount) {
    this._residue_count = residuecount;
  }
  
  public int getReplacement_count() {
    return this._replacement_count;
  }
  
  public void setReplacement_count(int replacement_count) {
    this._replacement_count = replacement_count;
  }
  
  public boolean isInputAmount() {
    return this._inputamount;
  }
  
  public void setInputAmount(boolean flag) {
    this._inputamount = flag;
  }
  
  public boolean isAll_In_Once() {
    return this._all_in_once;
  }
  
  public void setAll_In_Once(boolean flag) {
    this._all_in_once = flag;
  }
  
  public int getBonus_item() {
    return this._bonus_item;
  }
  
  public void setBonus_item(int bonusitem) {
    this._bonus_item = bonusitem;
  }
  
  public int getBonus_item_count() {
    return this._bonus_item_count;
  }
  
  public void setBonus_item_count(int bonusitemcount) {
    this._bonus_item_count = bonusitemcount;
  }
  
  public int getBonus_item_enchant() {
    return this._bonus_item_enchant;
  }
  
  public void setBonus_item_enchant(int bonusitemenchant) {
    this._bonus_item_enchant = bonusitemenchant;
  }
  
  public String get_sucesshtml() {
    return this._sucesshtml;
  }
  
  public void set_sucesshtml(String sucesshtml) {
    this._sucesshtml = sucesshtml;
  }
  
  public String get_runmessage() {
    return this._runmessage;
  }
  
  public void set_runmessage(String runmessage) {
    this._runmessage = runmessage;
  }
  
  public String get_failhtml() {
    return this._failhtml;
  }
  
  public void set_failhtml(String failhtml) {
    this._failhtml = failhtml;
  }
  
  public String get_Allmessage() {
    return this._Allmessage;
  }
  
  public void set_Allmessage(String Allmessage) {
    this._Allmessage = Allmessage;
  }
  
  public int getitembroad() {
    return this._itembroad;
  }
  
  public void setitembroad(int itembroad) {
    this._itembroad = itembroad;
  }
  
  public String get_othermessage() {
    return this._othermessage;
  }
  
  public void set_othermessage(String othermessage) {
    this._othermessage = othermessage;
  }
  
  public int getitemran() {
    return this._itemran;
  }
  
  public void setitemran(int itemran) {
    this._itemran = itemran;
  }
  
  public void setitemranup(int itemranup) {
    this._itemranup = itemranup;
  }
  
  public int getitemranup() {
    return this._itemranup;
  }
  
  public void ShowCraftHtml(L1PcInstance pc, L1NpcInstance npc, L1Blend ItemBlend) {
    String msg0 = "";
    String msg2 = "";
    String msg3 = "";
    String msg4 = "";
    String msg5 = "";
    String msg6 = "";
    String msg7 = "";
    String msg8 = "";
    String msg9 = "";
    String msg10 = "";
    String msg11 = "";
    String msg12 = "";
    String msg13 = "";
    String msg14 = "";
    String msg15 = "";
    String msg16 = "";
    String msg17 = "";
    String msg18 = "";
    String msg19 = "";
    String msg20 = "";
    String msg21 = "";
    L1ItemInstance Newitem = ItemTable.get().createItem(ItemBlend.getNew_item());
    if (Newitem != null) {
      Newitem.setCount(ItemBlend.getNew_item_counts());
      Newitem.setEnchantLevel(ItemBlend.getNew_item_Enchantlvl());
      Newitem.setIdentified(true);
      msg0 = Newitem.getLogName();
    } 
    L1ItemInstance Bonusitem = ItemTable.get().createItem(ItemBlend.getBonus_item());
    if (Bonusitem != null) {
      Bonusitem.setCount(ItemBlend.getBonus_item_count());
      Bonusitem.setEnchantLevel(ItemBlend.getBonus_item_enchant());
      Bonusitem.setIdentified(true);
      msg2 = "制造成功时额外获得: " + Bonusitem.getLogName();
    } 
    if (ItemBlend.getCheckLevel() != 0) {
      msg3 = " " + ItemBlend.getCheckLevel() + "级以上。 ";
    } else {
      msg3 = " 无限制 ";
    } 
    if (ItemBlend.getCheckClass() == 1) {
      msg4 = " 王族";
    } else if (ItemBlend.getCheckClass() == 2) {
      msg4 = " 骑士";
    } else if (ItemBlend.getCheckClass() == 3) {
      msg4 = " 法师";
    } else if (ItemBlend.getCheckClass() == 4) {
      msg4 = " 妖精";
    } else if (ItemBlend.getCheckClass() == 5) {
      msg4 = " 黑妖";
    } else if (ItemBlend.getCheckClass() == 6) {
      msg4 = " 龙骑士";
    } else if (ItemBlend.getCheckClass() == 7) {
      msg4 = " 幻术师";
    } else if (ItemBlend.getCheckClass() == 0) {
      msg4 = " 所有职业";
    } 
    if (ItemBlend.getRandom() != -1 && ItemBlend.get_runmessage() != null) {
      msg5 = " " + ItemBlend.get_runmessage();
    } else {
      msg5 = " " + ItemBlend.getRandom() + " %";
    } 
    int HammerRnd = CheckForFireHammerCount(pc, npc, ItemBlend);
    if (HammerRnd > 0 && ItemBlend.get_othermessage() != null)
      msg6 = "[" + ItemBlend.get_othermessage() + "]成功机率+: " + HammerRnd + " %"; 
    int[] Materials = ItemBlend.getMaterials();
    int[] counts = ItemBlend.getMaterials_count();
    int[] enchants = ItemBlend.get_materials_enchants();
    if (Materials != null) {
      int i = 0;
      while (i < Materials.length) {
        L1ItemInstance temp = ItemTable.get().createItem(Materials[i]);
        temp.setEnchantLevel(enchants[i]);
        temp.setIdentified(true);
        int replacementcount = ItemBlend.getReplacement_count();
        if (temp.getItemId() == 80028 && replacementcount != 0)
          msg7 = "可用(" + replacementcount + ")个火神痕迹替代火神契约"; 
        switch (i) {
          case 0:
            msg8 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 1:
            msg9 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 2:
            msg10 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 3:
            msg11 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 4:
            msg12 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 5:
            msg13 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 6:
            msg14 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 7:
            msg15 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 8:
            msg16 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 9:
            msg17 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 10:
            msg18 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 11:
            msg19 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 12:
            msg20 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
          case 13:
            msg21 = String.valueOf(String.valueOf(temp.getLogName())) + " (" + counts[i] + ") 个";
            break;
        } 
        i++;
      } 
    } 
    String[] msgs = { 
        msg0, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, 
        msg11, msg12, msg13, msg14, 
        msg15, msg16, msg17, msg18, msg19, msg20, 
        msg21 };
    pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(npc.getId(), "ItemBlend", msgs));
  }
  
  private boolean CheckForReplacement(L1PcInstance pc, L1Blend ItemBlend) {
    boolean replace = false;
    int replacement = 80322;
    int replacementcount = ItemBlend.getReplacement_count();
    if (replacementcount != 0 && pc.getInventory().checkItem(80322, replacementcount))
      replace = true; 
    return replace;
  }
  
  private int CheckForFireHammerCount(L1PcInstance pc, L1NpcInstance npc, L1Blend ItemBlend) {
    int HammerCount = 0;
    L1ItemInstance firehammer = pc.getInventory().findItemId(ItemBlend.getitemran());
    if (firehammer != null) {
      HammerCount = (int)firehammer.getCount();
      if (HammerCount > ItemBlend.getitemranup())
        HammerCount = ItemBlend.getitemranup(); 
    } 
    return HammerCount;
  }
  
  public void CheckCraftItem(L1PcInstance pc, L1NpcInstance npc, L1Blend ItemBlend, int amount, boolean checked) {
    int[] Materials = ItemBlend.getMaterials();
    int[] Materials_counts = ItemBlend.getMaterials_count();
    int[] enchants = ItemBlend.get_materials_enchants();
    if (checked || !ItemBlend.isInputAmount()) {
      boolean isok = true;
      int New_itemid = ItemBlend.getNew_item();
      int New_item_counts = ItemBlend.getNew_item_counts();
      L1ItemInstance newitem = ItemTable.get().createItem(New_itemid);
      if (New_itemid == 56148 && (
        pc.getInventory().findItemId(56147) != null || pc.getInventory().findItemId(56148) != null)) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上已有妲蒂斯的魔力。"));
        isok = false;
      } 
      if (New_itemid == 56147 && pc.getInventory().findItemId(56147) != null) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("身上已有妲蒂斯的魔力。"));
        isok = false;
      } 
      if (pc.getInventory().checkAddItem(newitem, New_item_counts) != 0)
        isok = false; 
      if (ItemBlend.getCheckLevel() != 0 && pc.getLevel() < ItemBlend.getCheckLevel()) {
        pc.sendPackets((ServerBasePacket)new S_ServerMessage("等级必须为" + ItemBlend.getCheckLevel() + "以上。"));
        isok = false;
      } 
      if (ItemBlend.getCheckClass() != 0) {
        byte class_id = 0;
        String Classmsg = "";
        if (pc.isCrown()) {
          class_id = 1;
        } else if (pc.isKnight()) {
          class_id = 2;
        } else if (pc.isWizard()) {
          class_id = 3;
        } else if (pc.isElf()) {
          class_id = 4;
        } else if (pc.isDarkelf()) {
          class_id = 5;
        } else if (pc.isDragonKnight()) {
          class_id = 6;
        } else if (pc.isIllusionist()) {
          class_id = 7;
        } 
        switch (ItemBlend.getCheckClass()) {
          case 1:
            Classmsg = "王族";
            break;
          case 2:
            Classmsg = "骑士";
            break;
          case 3:
            Classmsg = "法师";
            break;
          case 4:
            Classmsg = "妖精";
            break;
          case 5:
            Classmsg = "黑暗妖精";
            break;
          case 6:
            Classmsg = "龙骑士";
            break;
          case 7:
            Classmsg = "幻术士";
            break;
        } 
        if (ItemBlend.getCheckClass() != class_id) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "职业必须是", Classmsg, "才能制造此道具"));
          isok = false;
        } 
      } 
      if (ItemBlend.getHpConsume() != 0 || ItemBlend.getMpConsume() != 0) {
        if (pc.getCurrentHp() < ItemBlend.getHpConsume()) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "$1083", "必须有 (" + ItemBlend.getHpConsume() + ") ", 
                "才能使用此道具", "以上"));
          isok = false;
        } 
        if (pc.getCurrentMp() < ItemBlend.getMpConsume()) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, "$1084", "必须有 (" + ItemBlend.getMpConsume() + ") ", 
                "才能使用此道具", "以上"));
          isok = false;
        } 
      } 
      boolean enough = false;
      if (isok) {
        int num = 0;
        int i = 0;
        while (i < Materials.length) {
          if (Materials[i] != 0 && Materials_counts[i] != 0)
            if (Materials[i] == 80028 && !pc.getInventory().checkItem(Materials[i], Materials_counts[i]) && 
              CheckForReplacement(pc, ItemBlend)) {
              num++;
            } else if (!pc.getInventory().checkEnchantItem(Materials[i], enchants[i], 
                Materials_counts[i])) {
              L1ItemInstance temp = ItemTable.get().createItem(Materials[i]);
              temp.setEnchantLevel(enchants[i]);
              temp.setIdentified(true);
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(337, 
                    String.valueOf(String.valueOf(temp.getLogName())) + "(" + Materials_counts[i] + ")"));
              isok = false;
            } else {
              num++;
            }  
          i++;
        } 
        if (num == Materials.length)
          enough = true; 
      } 
      if (isok && enough) {
        if (ItemBlend.isAll_In_Once()) {
          int[] newcounts = new int[Materials_counts.length];
          int i = 0;
          while (i < Materials_counts.length) {
            newcounts[i] = Materials_counts[i] * amount;
            i++;
          } 
          i = 0;
          while (i < Materials.length) {
            pc.getInventory().consumeEnchantItem(Materials[i], enchants[i], newcounts[i]);
            i++;
          } 
        } else {
          int a = 0;
          while (a < amount) {
            int i = 0;
            while (i < Materials.length) {
              pc.getInventory().consumeEnchantItem(Materials[i], enchants[i], Materials_counts[i]);
              i++;
            } 
            a++;
          } 
        } 
        if (ItemBlend.getHpConsume() > 0)
          pc.setCurrentHp(pc.getCurrentHp() - ItemBlend.getHpConsume()); 
        if (ItemBlend.getMpConsume() > 0)
          pc.setCurrentMp(pc.getCurrentMp() - ItemBlend.getMpConsume()); 
        CraftItem(pc, npc, ItemBlend, amount);
        String sucesshtml = ItemBlend.get_sucesshtml();
        int DBrnd = ItemBlend.getRandom();
        if (sucesshtml != null && amount == 1 && DBrnd == 100)
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), sucesshtml)); 
      } else {
        String failhtml = ItemBlend.get_failhtml();
        int DBrnd = ItemBlend.getRandom();
        if (failhtml != null && amount == 1 && DBrnd == 100) {
          pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), failhtml));
        } else {
          pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
        } 
      } 
      return;
    } 
    long xcount = CreateNewItem.checkNewItem(pc, Materials, Materials_counts);
    if (xcount >= 1L) {
      pc.sendPackets((ServerBasePacket)new S_ItemCount(npc.getId(), (int)xcount, null));
      return;
    } 
    pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
  }
  
  private void CraftItem(L1PcInstance pc, L1NpcInstance npc, L1Blend ItemBlend, int amount) {
    Random _random = new Random();
    int DBrnd = ItemBlend.getRandom();
    int HammerRnd = CheckForFireHammerCount(pc, npc, ItemBlend);
    int TotalChance = DBrnd + HammerRnd;
    int New_itemid = ItemBlend.getNew_item();
    int New_item_counts = ItemBlend.getNew_item_counts();
    int Bonus_itemid = ItemBlend.getBonus_item();
    int Bonusitem_count = ItemBlend.getBonus_item_count();
    int Bonusitem_enchant = ItemBlend.getBonus_item_enchant();
    int ItemLV_SW = ItemBlend.getNew_Enchantlvl_SW();
    int ItemLV = ItemBlend.getNew_item_Enchantlvl();
    int ItemBless = ItemBlend.getNew_item_Bless();
    int ResdueItem = ItemBlend.getResidue_Item();
    int ResdueCount = ItemBlend.getResidue_Count();
    String npcName = npc.getNpcTemplate().get_name();
    int newamount = amount;
    int newcounts = New_item_counts;
    if (ItemBlend.isAll_In_Once()) {
      newamount = 1;
      newcounts = New_item_counts * amount;
    } 
    int i = 0;
    while (i < newamount) {
      if (_random.nextInt(100) + 1 <= TotalChance) {
        L1ItemInstance newitem = ItemTable.get().createItem(New_itemid);
        if (newitem != null && pc.getInventory().checkAddItem(newitem, newcounts) == 0)
          if (newitem.isStackable()) {
            if (ItemLV_SW == 0) {
              newitem.setEnchantLevel(ItemLV);
              newitem.setBless(ItemBless);
              newitem.setIdentified(true);
            } else {
              newitem.setEnchantLevel(_random.nextInt(ItemLV) + 1);
              newitem.setBless(ItemBless);
              newitem.setIdentified(true);
            } 
            newitem.setCount(newcounts);
            pc.getInventory().storeItem(newitem);
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(143, npcName, newitem.getLogName()));
            if (ItemBlend.getitembroad() > 0 && ItemBlend.get_Allmessage() != null)
              World.get().broadcastPacketToAll((ServerBasePacket)new S_SystemMessage(
                    String.format(ItemBlend.get_Allmessage(), new Object[] { pc.getName(), newitem.getLogName() }))); 
            firenpc("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + 
                "成功铸造" + newitem.getLogName() + "(" + newcounts + ")" + " 】,时间:" + "(" + 
                new Timestamp(System.currentTimeMillis()) + ")。");
          } else {
            int c = 0;
            while (c < newcounts) {
              L1ItemInstance newitem2 = ItemTable.get().createItem(New_itemid);
              if (ItemLV_SW == 0) {
                newitem2.setEnchantLevel(ItemLV);
                newitem2.setBless(ItemBless);
                newitem2.setIdentified(true);
              } else {
                newitem2.setEnchantLevel(_random.nextInt(ItemLV) + 1);
                newitem2.setBless(ItemBless);
                newitem2.setIdentified(true);
              } 
              newitem2.setCount(1L);
              pc.getInventory().storeItem(newitem2);
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(143, npcName, newitem2.getLogName()));
              if (ItemBlend.getitembroad() > 0 && ItemBlend.get_Allmessage() != null)
                World.get().broadcastPacketToAll((ServerBasePacket)new S_SystemMessage(
                      String.format(ItemBlend.get_Allmessage(), new Object[] { pc.getName(), newitem.getLogName() }))); 
              firenpc("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + 
                  "成功铸造" + newitem.getLogName() + "(" + newcounts + ")" + " 】,时间:" + "(" + 
                  new Timestamp(System.currentTimeMillis()) + ")。");
              c++;
            } 
          }  
        L1ItemInstance bonusitem = ItemTable.get().createItem(Bonus_itemid);
        if (bonusitem != null && pc.getInventory().checkAddItem(bonusitem, Bonusitem_count) == 0)
          if (bonusitem.isStackable()) {
            bonusitem.setEnchantLevel(Bonusitem_enchant);
            bonusitem.setIdentified(true);
            bonusitem.setCount(Bonusitem_count);
            pc.getInventory().storeItem(bonusitem);
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(143, npcName, bonusitem.getLogName()));
          } else {
            int c2 = 0;
            while (c2 < Bonusitem_count) {
              L1ItemInstance bonusitem2 = ItemTable.get().createItem(Bonus_itemid);
              bonusitem2.setEnchantLevel(Bonusitem_enchant);
              bonusitem2.setIdentified(true);
              bonusitem2.setCount(1L);
              pc.getInventory().storeItem(bonusitem2);
              pc.sendPackets((ServerBasePacket)new S_ServerMessage(143, npcName, bonusitem2.getLogName()));
              c2++;
            } 
          }  
      } else {
        L1ItemInstance residueitem = ItemTable.get().createItem(ResdueItem);
        if (residueitem != null && ResdueCount > 0) {
          if (pc.getInventory().checkAddItem(residueitem, ResdueCount) == 0) {
            residueitem.setCount(ResdueCount);
            pc.getInventory().storeItem(residueitem);
            pc.sendPackets((ServerBasePacket)new S_ServerMessage(143, npcName, residueitem.getLogName()));
            pc.sendPackets((ServerBasePacket)new S_SystemMessage("道具制造失败了"));
            firenpcfail("IP(" + pc.getNetConnection().getIp() + ")" + "玩家" + ":【 " + pc.getName() + " 】 " + 
                "失败铸造" + residueitem.getLogName() + "(" + newcounts + ")" + " 】,时间:" + "(" + 
                new Timestamp(System.currentTimeMillis()) + ")。");
          } 
        } else {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("道具制造失败了"));
        } 
      } 
      int Hammercount = CheckForFireHammerCount(pc, npc, ItemBlend);
      if (Hammercount > 0)
        pc.getInventory().consumeItem(ItemBlend.getitemran(), Hammercount); 
      i++;
    } 
    pc.sendPackets((ServerBasePacket)new S_CloseList(pc.getId()));
  }
  
  public static void firenpc(String info) {
    PlayerLogUtil.writeLog("制作NPC记录", info);
  }
  
  public static void firenpcfail(String info) {
    PlayerLogUtil.writeLog("制作NPC失败记录", info);
  }
}
